Thread: [ISO] Notation for mathematical intervals

  1. #1
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446

    [ISO] Notation for mathematical intervals

    Under ISO 31-11, I could write ]2,5[ or (2,5). Both square brackets and parenthesis were accepted symbols for open ends on either side of the interval.

    However ISO 80000-2:2009 supersedes it and I can't seem to find any reliable access to the text. Do you know if this remains the case in the new ISO?
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  2. #2
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Whoa... This is freaky. I literally have been looking for a way to notate this today. I eventually settled with :
    Code:
    //typedef float real;
    typedef double real;
    
    inline
    bool elem_of(real x, real a, real b)
    {
        return (x > a && x < b);
    }

  3. #3
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Make them UDTs, overwrite their logical operators and write something more beautiful, like:

    return (a < x < b);
    Or don't.

    Also, that typedef is hurting my eyes.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  4. #4
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    Make them UDTs, overwrite their logical operators and write something more beautiful, like:
    O_o

    You'll find that a bad idea. The C++ language has no way to express differentiation of a boolean context from an arithmetic context without transforming the expression into a type.

    *shrug*

    Anyways, I found what I could of your other threads. (I refuse to sign a forum I'm not interested in actively participating.) I have to ask, why do you want to use the bracket form so much? I don't care. I'm just curious why the parenthesis is unacceptable?

    To be honest, I'm also wondering why you couldn't use a markup of some sort allowing the reader to use whichever form with which they are most familiar.

    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  5. #5
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Quote Originally Posted by Mario F. View Post
    Make them UDTs, overwrite their logical operators and write something more beautiful, like:



    Or don't.

    Also, that typedef is hurting my eyes.
    It's like the best way of switching between relevant mathematical types that isn't templating.

    Templates would be cool but the problem is, they allow any​ type (like char or bool). I want to keep it float or double that way my code can change on the fly with actual relevant types.

  6. #6
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    Templates would be cool but the problem is, they allow any​ type (like char or bool).
    O_o

    Rubbish. If an expansion is invalid, you can blacklist the relevant types.

    *shrug*

    You could just whitelist `float`, `double`, and `long double` types if you can only use something like real numbers.

    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  7. #7
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by phantomotap View Post
    Anyways, I found what I could of your other threads. (I refuse to sign a forum I'm not interested in actively participating.) I have to ask, why do you want to use the bracket form so much? I don't care. I'm just curious why the parenthesis is unacceptable?
    During my early days, I learned with the brackets form. So parenthesis look as weird to me as the brackets do to you. During my undergrad days I started to gain access to Anglo-Saxon texts and I realized you used parenthesis, while Latin countries tended to use the brackets. It seems to be (or have been at some point) a cultural thing.

    I'm not much concerned which one I use. As long as it is well defined. It's just that I was having a discussion with a colleague of mine that insisted the new standard removed the brackets form. Since I do teach college mathematics and I tell my students of both forms, I'd like a confirmation this is the case.

    Did get an answer somewhere else. Both forms remain.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  8. #8
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by phantomotap View Post
    You'll find that a bad idea. The C++ language has no way to express differentiation of a boolean context from an arithmetic context without transforming the expression into a type.
    I'm most definitely rusty of my C++, but wasn't it possible to chain boolean operations?
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  9. #9
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    [Edit]
    Overshoot.

    *sigh*

    Yes. You can chain virtually any operator for a custom type, but the result of chaining operators returning a boolean value doesn't do what the expression implies you expect because each new link in the chain only results in a boolean value.
    [/Edit]

    I'm most definitely rusty of my C++, but wasn't it possible to chain boolean operations?
    O_o

    Yes. In fact, you'd have to overload one such operator for the differentiation to work.

    The problem is that, without transforming the expression into a type, none of `operator bool()`, `bool operator < (UDT, UDT)`, or `UDT operator < (UDT, UDT)` are aware of which you want to call in the context of the proposed expression which means that simply overloading those operators produces unexpected results. You can't even have both forms of the comparison operator. (You'd find the expression ambiguous, so compilation would not be successful, if you could have both forms.) You have to choose how the fragment `a < x` behaves in the context of the proposed expression or change the types of the parameters.

    The `bool operator < (UDT, UDT)` form returns a value unrelated to the input with respect to the expression leaving you with a `true < b` fragment or a `false < b` fragment. You could overload `bool operator < (bool, UDT)` which allows the chaining, but you've lost the input value so have no way of comparing to the limit.

    The `UDT operator < (UDT, UDT)` form returns a value of type `UDT` which allows chaining while propagating the relevant value. The chaining calls the same form of the operator, but you don't want a value of type `UDT` for the `UDT < b` fragment. You want a boolean result from the `UDT < b` fragment. You could overload the `operator bool` or similar method, but you've not stored the result of the comparison so whatever you return isn't related to the relationship between `this` and the `b` value. Of course, you could store the result of the comparison; you'd have to modify the input for a comparison function which is rather stupid.

    You need to propagate the relevant values and the result of comparison in the fragment `a < x` for the expression `a < x < b` to have the intended semantics. You can store the values and the result in infinitely many ways, but you'll eventually wind up with some `UDTComparisonResult` which has the relevant `UDTComparisonResult operator < (UDTComparisonResult, UDT)` and `operator bool` overloads.

    *shrug*

    Personally, I'd go with the logically combined form rather than play games with types and operators.

    o_O

    Well, I've done exactly that for practice. I don't use such a thing in real code.

    Soma
    Last edited by phantomotap; 07-06-2015 at 06:13 AM.
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  10. #10
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Quote Originally Posted by Mario F. View Post
    During my early days, I learned with the brackets form. So parenthesis look as weird to me as the brackets do to you. During my undergrad days I started to gain access to Anglo-Saxon texts and I realized you used parenthesis, while Latin countries tended to use the brackets. It seems to be (or have been at some point) a cultural thing..
    Isn't it a math thing and not a culture thing?

    Like x as an element of (0, 1) means 0 < x < 1 while x as an element of [0, 1] means 0 <= x <= 1.

    Quote Originally Posted by phantomotap View Post
    O_o


    Rubbish. If an expansion is invalid, you can blacklist the relevant types.


    *shrug*


    You could just whitelist `float`, `double`, and `long double` types if you can only use something like real numbers.


    Soma

    How would I go about doing something like this?

  11. #11
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    Isn't it a math thing and not a culture thing?
    O_o

    You'll find that `]0, 1[` is different than `[0, 1]`.

    How would I go about doing something like this?
    You've been shown examples, by more than just me, of how to place limits on the acceptable types.

    I suggest you study the examples.

    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  12. #12
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    I've been shown examples on how to limit templates types? When? O_o

    I seriously don't remember that... Hmm... Fine. To google!!!!

  13. #13
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by MutantJohn View Post
    Isn't it a math thing and not a culture thing?
    I explained why it isn't a "math thing" in post #1.

    Both forms are acceptable. The question was only if the new standard that supersedes the old one, this was still the case. And it still is.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. openMP - intervals assigned to threads
    By überfuzz in forum C++ Programming
    Replies: 6
    Last Post: 02-10-2014, 05:42 AM
  2. Replies: 77
    Last Post: 10-15-2011, 04:45 PM
  3. Quick question on mathematical notation (translating to C)
    By gardhr in forum General Discussions
    Replies: 16
    Last Post: 09-17-2011, 12:00 AM
  4. Connecting intervals together
    By kaspari22 in forum C++ Programming
    Replies: 5
    Last Post: 06-24-2011, 11:32 AM
  5. Expression: Convert infix notation to postfix notation.
    By Nutshell in forum C Programming
    Replies: 7
    Last Post: 02-27-2010, 07:44 AM